define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form,undefined) {

    var Controller = {
        //用户信息列表
        //用户信息列表
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'qzuser/qzuser/index',
                    add_url: 'qzuser/qzuser/add',
                    edit_url: 'qzuser/qzuser/edit',
                    updatestatus_url: 'user/user/multi',
                    table: 'qzuser/qzuser',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'userid',
                sortName: '',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID'), sortable: true},
                        {field: 'userid', title: __('账号'), sortable: true},
                        {field: 'img', title: __('头像'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'nickname', title: __('昵称'),operate: 'LIKE'},
                        {field: 'diqu', title: __('地区'),visible: false},
                        {field: 'sex', title: __('性别'), visible: false,},
                        {field: 'age', title: __('年龄'),operate: 'BETWEEN'},
                        {field: 'tige', title: __('身高/体重'),visible: false},
                        {field: 'phone', title: __('手机号')},
                        {field: 'use_type', title: __('用户身份'), visible: false, searchList: {1: __('普通'), 2: __('达人'),3:__('商家')}},
                        {field: 'prased', title: __('获赞量'),editable: true,sortable: true,operate:false},
                        {field: 'card_num', title: __('体验卡数量'),editable: true,visible: false,operate:false},
                        {field: 'creat_time', title: __('创建时间'),formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        { field: 'status', title: __('状态'), operate: false, formatter: Controller.api.formatter.status},
                        {
                            field: 'buttons',
                            width: "220px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'edit',
                                    text: __('编辑'),
                                    title: __('编辑'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'qzuser/qzuser/edit',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'addtabs',
                                    text: __('查看'),
                                    title: __('查看详情'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-folder-o',
                                    url: 'qzuser/qzuser/detail'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                    ]
                ]

            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();

        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                status: function (value, row, index) {
                    //添加上btn-change可以自定义请求的URL进行数据处理
                    return '<a class="btn-change text-success" data-url="qzuser/qzuser/updatestatus" data-id="' + row.userid + '" data-params="'+row.status+'"><i class="fa ' + (row.status == '0' ? 'fa-toggle-off' : 'fa-toggle-on') + ' fa-2x"></i></a>';
                },
            },
        }
    };
    return Controller;
});